/***************************************************************************//**
 * @file MSc_DataRef.h
 * @author  Marek M. Cel <marekcel@mscsim.org>
 *
 * @section LICENSE
 *
 * Copyright (C) 2014 Marek M. Cel
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 ******************************************************************************/
#ifndef MSC_DATA_REF_H
#define MSC_DATA_REF_H

////////////////////////////////////////////////////////////////////////////////

#include <limits>

#include <MSc_Defs.h>

#include "MSc_Argument.h"
#include "MSc_DataNode.h"

////////////////////////////////////////////////////////////////////////////////

/** Data reference class. */
class MSc_DataRef : public MSc_Argument
{
public:

    /** Constructor. */
    MSc_DataRef( MSc_DataNode *dataNode = 0 ) : m_dataNode( dataNode ) {}

    /** Copy constructor. */
    MSc_DataRef( const MSc_DataRef &dataRef )
    {
        m_dataNode = dataRef.m_dataNode;
    }

    /** Destructor. */
    virtual ~MSc_DataRef() {}

    /** @return Data value on success or NaN on failure. */
    inline bool getDatab() const
    {
        if ( m_dataNode )
        {
            return m_dataNode->getDatab();
        }

        return std::numeric_limits< bool >::quiet_NaN();
    }

    /** @return Data value on success or NaN on failure. */
    inline int getDatai() const
    {
        if ( m_dataNode )
        {
            return m_dataNode->getDatai();
        }

        return std::numeric_limits< int >::quiet_NaN();
    }

    /** @return Data value on success or NaN on failure. */
    inline long getDatal() const
    {
        if ( m_dataNode )
        {
            return m_dataNode->getDatal();
        }

        return std::numeric_limits< long >::quiet_NaN();
    }

    /** @return Data value on success or NaN on failure. */
    inline float getDataf() const
    {
        if ( m_dataNode )
        {
            return m_dataNode->getDataf();
        }

        return std::numeric_limits< float >::quiet_NaN();
    }

    /** @return Data value on success or NaN on failure. */
    inline double getDatad() const
    {
        if ( m_dataNode )
        {
            return m_dataNode->getDatad();
        }

        return std::numeric_limits< double >::quiet_NaN();
    }

    /** @return Data value on success or NaN on failure. */
    inline double getValue() const
    {
        if ( m_dataNode )
        {
            return m_dataNode->getValue();
        }

        return std::numeric_limits< double >::quiet_NaN();
    }

    /** @return MSCFDM_SUCCESS on success or MSCFDM_FAILURE on failure. */
    inline int setDatab( bool value )
    {
        if ( m_dataNode )
        {
            return m_dataNode->setDatab( value );
        }

        return MSCFDM_FAILURE;
    }

    /** @return MSCFDM_SUCCESS on success or MSCFDM_FAILURE on failure. */
    inline int setDatai( int value )
    {
        if ( m_dataNode )
        {
            return m_dataNode->setDatai( value );
        }

        return MSCFDM_FAILURE;
    }

    /** @return MSCFDM_SUCCESS on success or MSCFDM_FAILURE on failure. */
    inline int setDatal( long value )
    {
        if ( m_dataNode )
        {
            return m_dataNode->setDatal( value );
        }

        return MSCFDM_FAILURE;
    }

    /** @return MSCFDM_SUCCESS on success or MSCFDM_FAILURE on failure. */
    inline int setDataf( float value )
    {
        if ( m_dataNode )
        {
            return m_dataNode->setDataf( value );
        }

        return MSCFDM_FAILURE;
    }

    /** @return MSCFDM_SUCCESS on success or MSCFDM_FAILURE on failure. */
    inline int setDatad( double value )
    {
        if ( m_dataNode )
        {
            return m_dataNode->setDatad( value );
        }

        return MSCFDM_FAILURE;
    }

private:

    MSc_DataNode *m_dataNode;   ///< data node pointer
};

////////////////////////////////////////////////////////////////////////////////

#endif // MSC_DATA_REF_H
